<template>
	<div class="app-container">
		<el-form ref="formData" :model="formData" label-width="110px">
			<el-form-item label="原库存数量：">
			  {{teaData.inventory.inventory}}
			</el-form-item>
			<el-form-item label="新增库存数量：">
				<el-input v-model="formData.addNum" placeholder="请输入数量" @blur="addnum" :disabled="addFlag"></el-input>
			</el-form-item>
			<el-form-item label="修正库存数量：">
				<el-input v-model="formData.editNum" placeholder="请输入数量" @blur="editnum" :disabled="editFlag"></el-input>
			</el-form-item>
			<el-form-item label="备注：">
				<el-input v-model="formData.info" type="area"></el-input>
			</el-form-item>
			<el-form-item label="操作人：">
			  {{username}}
			</el-form-item>
			<div style="text-align: center;">
				<el-button type="primary" @click="ware" :disabled="addFlag == false&&editFlag == false">提交</el-button>
				<el-button type="danger" @click="rest">重置</el-button>
			</div>
		</el-form>
	</div>
</template>

<script>
import { addUpdate } from '@/api/studentRecruit.js'
import store from '../../../../store' // get token
export default {
	components:{
		
	},
	data() {
		return{
			formData:{
				unid:'',
				addNum:'',
				editNum:'',
				oldNum:'',
				info:'',
			},
			username:store.getters.name,
			addFlag:false,
			editFlag:false,
		}
	},
	created() {
		console.log(this.teaData);
		console.log(this.username);
	},
	methods:{
		//重置
		rest(){
			Object.keys(this.formData).forEach(key => {
				this.formData[key] = ''
			})
		},
		//修改库存
		async ware(){
			this.formData.unid = this.teaData.unid
			this.formData.oldNum = this.teaData.inventory.inventory
			let data = await addUpdate(this.formData)
			if(data.code == 200){
				this.$message.success('修改成功！')
				if(this.formData.addNum){
					this.teaData.inventory.inventory = this.teaData.inventory.inventory+parseInt(this.formData.addNum)
				}else if(this.formData.editNum){
					this.teaData.inventory.inventory = parseInt(this.formData.editNum)
				}
				Object.keys(this.formData).forEach(key => {
					this.formData[key] = ''
				})
			}else{
				this.$message.error('修改失败！')
			}
		},
		//新增库存输入框
		addnum(){
			console.log('输入框焦点');
			if(this.formData.addNum){
				this.editFlag = true
				this.formData.editNum = ''
			}else{
				this.editFlag = false
			}
		},
		//修改库存输入框
		editnum(){
			console.log('输入框焦点');
			if(this.formData.editNum){
				this.addFlag = true
				this.formData.addNum = ''
			}else{
				this.addFlag = false
			}
		},
	},
	props:{
		teaData:{
			type:Object,
			default:{}
		}
	}
}
</script>

<style>
	
</style>
